// exports.AL_Framework_Bit_Encrypt = void 0;
// var i = (function () {
//     function e() {
//         this.logTag = "[AL_Framework_Bit_Encrypt]:";
//         this._jiamiMiyao = "EskKbMvzZBILhcTv";
//     }
//     Object.defineProperty(e.prototype, "jiamiMiyao", {
//         get: function () {
//             return this._jiamiMiyao;
//         },
//         set: function (e) {
//             this._jiamiMiyao = e;
//         },
//         enumerable: !1,
//         configurable: !0
//     });
//     e.prototype.decode = function (e, t) {
//         return this._neibuBIanmaLuoji(e, t);
//     };
//     e.prototype.encode = function (e, t) {
//         return this._neibuBIanmaLuoji(e, t);
//     };
//     e.prototype._neibuBIanmaLuoji = function (e, t) {
//         var o = this._jiancha(e, t);
//         if (o.isOK) {
//             var i = [];
//             for (var n = 0; n < e.length; n++) {
//                 i.push(e.charCodeAt(n));
//             }
//             var a = 0;
//             var s = /[\w\d_-`~#!$%^&*(){}=+;:'"<,>,/?|\\\u4e00-\u9fa5]/g;
//             for (n = 0; n < i.length; n++) {
//                 var r = e[n].match(s);
//                 if (r && r.length > 0) {
//                     i[n] ^= o.key.charCodeAt(a);
//                     if (!((r = String.fromCharCode(i[n]).match(s)) && r.length)) {
//                         i[n] ^= o.key.charCodeAt(a);
//                     }
//                     if (++a >= o.key.length) {
//                         a = 0;
//                     }
//                 }
//             }
//             var c = "";
//             for (n = 0; n < i.length; n++) {
//                 c += String.fromCharCode(i[n]);
//             }
//             return c;
//         }
//         return e;
//     };
//     e.prototype._jiancha = function (e, t) {
//         return e && e.length > 0
//             ? t && t.length > 0
//                 ? {
//                       isOK: !0,
//                       key: t
//                   }
//                 : this.jiamiMiyao && this.jiamiMiyao.length > 0
//                 ? {
//                       isOK: !0,
//                       key: this.jiamiMiyao
//                   }
//                 : {
//                       isOK: !1,
//                       key: ""
//                   }
//             : {
//                   isOK: !1,
//                   key: ""
//               };
//     };
//     return e;
// })();
// exports.AL_Framework_Bit_Encrypt = new i();
// window.AL_Framework_Bit_Encrypt = exports.AL_Framework_Bit_Encrypt;

/**
 * BitEncrypt类用于进行简单的加密和解密操作
 */
class AL_Framework_Bit_Encrypt {
    /**
     * 构造函数，初始化加密密钥
     */
    constructor() {
        this.logTag = "[AL_Framework_Bit_Encrypt]:";
        // this._jiamiMiyao = "EskKbMvzZBILhcTv";
        this._jiamiMiyao = "VskKbMazZBILhcTe";
    }

    /**
     * 获取加密密钥
     * @return {string} 加密密钥
     */
    get jiamiMiyao() {
        return this._jiamiMiyao;
    }

    /**
     * 设置加密密钥
     * @param {string} key 加密密钥
     */
    set jiamiMiyao(key) {
        this._jiamiMiyao = key;
    }

    /**
     * 解码函数
     * @param {string} data 要解码的字符串
     * @param {string} key 解码密钥
     * @return {string} 解码后的字符串
     */
    decode(data, key) {
        return this._neibuBIanmaLuoji(data, key);
    }

    /**
     * 编码函数
     * @param {string} data 要编码的字符串
     * @param {string} key 编码密钥
     * @return {string} 编码后的字符串
     */
    encode(data, key) {
        return this._neibuBIanmaLuoji(data, key);
    }

    /**
     * 内部编码解码逻辑
     * @param {string} data 要编码或解码的字符串
     * @param {string} key 编码或解码密钥
     * @return {string} 编码或解码后的字符串
     */
    _neibuBIanmaLuoji(data, key) {
        const checkResult = this._jiancha(data, key);
        if (checkResult.isOK) {
            const charCodes = [];
            for (let i = 0; i < data.length; i++) {
                charCodes.push(data.charCodeAt(i));
            }

            let keyIndex = 0;
            const validCharRegex = /[\w\d_-`~#!$%^&*(){}=+;:'"<,>,/?|\\\u4e00-\u9fa5]/g;

            for (let i = 0; i < charCodes.length; i++) {
                const match = data[i].match(validCharRegex);
                if (match && match.length > 0) {
                    charCodes[i] ^= checkResult.key.charCodeAt(keyIndex);
                    if (!(String.fromCharCode(charCodes[i]).match(validCharRegex) && match.length)) {
                        charCodes[i] ^= checkResult.key.charCodeAt(keyIndex);
                    }
                    if (++keyIndex >= checkResult.key.length) {
                        keyIndex = 0;
                    }
                }
            }

            let result = "";
            for (let i = 0; i < charCodes.length; i++) {
                result += String.fromCharCode(charCodes[i]);
            }
            return result;
        }
        return data;
    }

    /**
     * 检查输入数据和密钥的有效性
     * @param {string} data 输入数据
     * @param {string} key 输入密钥
     * @return {object} 检查结果，包含isOK和key两个属性
     */
    _jiancha(data, key) {
        if (data && data.length > 0) {
            if (key && key.length > 0) {
                return { isOK: true, key: key };
            } else if (this.jiamiMiyao && this.jiamiMiyao.length > 0) {
                return { isOK: true, key: this.jiamiMiyao };
            }
        }
        return { isOK: false, key: "" };
    }
}

exports.AL_Framework_Bit_Encrypt = new AL_Framework_Bit_Encrypt();
window.AL_Framework_Bit_Encrypt = exports.AL_Framework_Bit_Encrypt;
